@extends('backend::common.common_right')
@section('content')
    <style>
        #file {position: absolute;left: 0;width: 100%;height: 100%;top: 0;opacity: 0;z-index: 2;cursor: pointer;}
        #show_img{border:1px solid #eee;width:100%;height: 100%;}
        .lazy{width:500px;}
        .upload_file {border:1px solid #eee; position: absolute;left: 0;width: 100%;height: 100%;top: 0;opacity: 0;z-index: 2;cursor: pointer;}
        .show_img{border:1px solid #eee;width:100%;height: 100%;}
    </style>
    <div class="wrapper wrapper-content animated fadeInRight">
        <div class="row">
            <div class="col-sm-12">
                <div class="ibox-title">
                    <h5>添加/编辑软件</h5>
                    <div class="ibox-tools">
                        <a class="close-link" href="javascript:history.go(-1);">
                            <i class="fa fa-times" ></i>
                        </a>
                    </div>
                </div>
                    <div class="ibox-content">
                        <form class="form-horizontal m-t" onsubmit="return checkcat()" action="{{url('backend/appedit')}}" method="post">
                            {{ csrf_field() }}
                            <input type="hidden" name="id" value="{{$app->id or ''}}">
                            <div class="form-group{{ $errors->has('appcatid') ? ' has-error' : '' }}" >
                                <label class="col-sm-3 control-label">软件分类：</label>
                                <div class="col-sm-8">
                                    <div class="col-sm-6 row">
                                        <select class="form-control catsshow" name="appcatid" id="appcatid">
                                        <option value="0">全部</option>
                                        @foreach($cats as $c)
                                                <option value="{{$c->id}}"@isset($app) @if($app->appcatid == $c->id) selected @endif @endisset >{{$c->catname}}</option>
                                        @endforeach
                                        </select>
                                    </div>
                                </div>
                                @if ($errors->has('cat_id1'))
                                    <span class="help-block">
                                    <strong>{{ $errors->first('cat_id1') }}</strong>
                                    </span>
                                @endif
                            </div>
                            <div class="form-group{{ $errors->has('title') ? ' has-error' : '' }}">
                                <label class="col-sm-3 control-label">软件名称：</label>
                                <div class="col-sm-8">
                                    <input type="text"  value="{{ $app->title or '' }}" name="title" class="form-control" placeholder="请输入软件名称" id="title">
                                    @if ($errors->has('title'))
                                        <span class="help-block">
                                        <strong>{{ $errors->first('title') }}</strong>
                                    </span>
                                    @endif
                                </div>
                            </div>
                            <div class="form-group"{{ $errors->has('logo') ? ' has-error' : '' }}>
                                <label class="col-sm-3 control-label">封面：</label>
                                <div class="col-sm-8">
                                    <div class="col-sm-2" id="aetherupload-wrapper" style="height: 100px;position: relative;padding:0;">
                                        <img class="show_img" src="{{env('APP_IMGSMAllURL')}}{{$app->logo or 'images/default.png'}}"  alt="">
                                        <input id="file" class="upload_file" onchange="aetherupload(this,'image').success(someoneCallback).upload()" type="file" val=""/>
                                        <input type="hidden" name="logo" id="savedpath" value="{{$app->logo or ''}}">
                                        <span style="font-size:12px;color:#aaa;"  id="output"></span>
                                    </div>
                                    @if ($errors->has('logo'))
                                        <span class="help-block">
                                                 <strong>{{ $errors->first('logo') }}</strong>
                                             </span>
                                    @endif
                                </div>
                            </div>
                            <div class="form-group{{ $errors->has('time') ? ' has-error' : '' }}">
                                <label class="col-sm-3 control-label">发布时间：</label>
                                <div class="col-sm-3">

                                    <input type="date" value="{{ $app->time or '' }}" name="time" class="form-control" placeholder="请输入软件名称" id="time">
                                    @if ($errors->has('time'))
                                        <span class="help-block">
                                        <strong>{{ $errors->first('time') }}</strong>
                                    </span>
                                    @endif
                                </div>
                            </div>
                            <div class="form-group{{ $errors->has('size') ? ' has-error' : '' }}">
                                <label class="col-sm-3 control-label">大小：</label>
                                <div class="col-sm-8">
                                    <input type="text" value="{{ $app->size or '' }}" name="size" class="form-control" placeholder="请输入软件名称">
                                    @if ($errors->has('size'))
                                        <span class="help-block">
                                        <strong>{{ $errors->first('size') }}</strong>
                                    </span>
                                    @endif
                                </div>
                            </div>
                            <div class="form-group{{ $errors->has('version') ? ' has-error' : '' }}">
                                <label class="col-sm-3 control-label">版本：</label>
                                <div class="col-sm-8">
                                    <input type="text" value="{{ $app->version or '' }}" name="version" class="form-control" placeholder="请输入软件版本">
                                    @if ($errors->has('version'))
                                        <span class="help-block">
                                        <strong>{{ $errors->first('version') }}</strong>
                                    </span>
                                    @endif
                                </div>
                            </div>
                            <div class="form-group{{ $errors->has('supportsystem') ? ' has-error' : '' }}">
                                <label class="col-sm-3 control-label">支持系统：</label>
                                <div class="col-sm-8">
                                    <input type="text" value="{{ $app->supportsystem or '' }}" name="supportsystem" class="form-control" placeholder="请输入软件支持系统">
                                    @if ($errors->has('supportsystem'))
                                        <span class="help-block">
                                        <strong>{{ $errors->first('supportsystem') }}</strong>
                                    </span>
                                    @endif
                                </div>
                            </div>
                            <div class="form-group{{ $errors->has('url') ? ' has-error' : '' }}">
                                <label class="col-sm-3 control-label">官网：</label>
                                <div class="col-sm-8">
                                    <input type="text" value="{{ $app->url or '' }}" name="url" class="form-control" placeholder="请输入软件官网">
                                    @if ($errors->has('url'))
                                        <span class="help-block">
                                        <strong>{{ $errors->first('url') }}</strong>
                                    </span>
                                    @endif
                                </div>
                            </div>
                            <div class="form-group{{ $errors->has('downurl') ? ' has-error' : '' }}">
                                <label class="col-sm-3 control-label">下载地址：</label>
                                <div class="col-sm-8">
                                    <input type="text" value="{{ $app->downurl or '' }}" name="downurl" class="form-control" placeholder="请输入软件下载地址">
                                    @if ($errors->has('downurl'))
                                        <span class="help-block">
                                        <strong>{{ $errors->first('downurl') }}</strong>
                                    </span>
                                    @endif
                                </div>
                            </div>
                            <div class="form-group">
                                <div class="col-sm-9 col-sm-offset-2">
                                    <script type="text/plain" id="myEditor" name="content" style="width:100%;height:240px;">{!! $app->content or '' !!}
                                    </script>
                                </div>
                            </div>
                            <div class="form-group">
                                <div class="col-sm-8 col-sm-offset-3">
                                    <button class="btn btn-primary" type="submit">提交</button>
                                </div>
                            </div>
                        </form>
                    </div>
                </div>
            </div>
        </div>
    </div>
    <link href="{{ URL::asset('admin/js/plugins/ueditor/themes/default/css/umeditor.css')}}" rel="stylesheet">
    <script  src="{{ URL::asset('admin/js/plugins/ueditor/third-party/jquery.min.js')}}"></script>
    <script  charset="utf-8" src="{{ URL::asset('admin/js/plugins/ueditor/umeditor.config.js')}}"></script>
    <script  charset="utf-8" src="{{ URL::asset('admin/js/plugins/ueditor/umeditor.min.js')}}"></script>
    <script  charset="utf-8" src="{{ URL::asset('admin/js/plugins/ueditor/lang/zh-cn/zh-cn.js')}}"></script>
    <script src="{{URL::asset('admin/js/jquery.lazyload.js')}}"></script><script>
        var um = UM.getEditor('myEditor');
        var  checkcat = function(){
            if ($("#appcatid").val() == 0) {
                layer.alert('请选择分类后在上传', {icon: 5});
                return false;
            }
        }
        someoneCallback = function(){
            var show_img = this.wrapperDom.find(".show_img");
            var path =  '/storage/' + this.savedPath;
            show_img.attr('src', path);
        }
    </script>

@endsection